<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Get the status of a background job</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="gearmanclient.geterrno.html">GearmanClient::getErrno</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="gearmanclient.ping.html">GearmanClient::ping</a></div>
 <div class="up"><a href="class.gearmanclient.html">GearmanClient</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="gearmanclient.jobstatus" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">GearmanClient::jobStatus</h1>
  <h1 class="refname">gearman_job_status</h1>
  <p class="verinfo">(PECL gearman &gt;= 0.5.0)</p><p class="refpurpose"><span class="refname">GearmanClient::jobStatus</span> -- <span class="refname">gearman_job_status</span> &mdash; <span class="dc-title">Get the status of a background job</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-gearmanclient.jobstatus-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格 (method):</p>
   <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">array</span> <span class="methodname"><strong>GearmanClient::jobStatus</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$job_handle</code></span>
    )</div>

   <p class="para rdfs-comment">
    Gets the status for a background job given a job handle.  The status information will
    specify whether the job is known, whether the job is currently running, and
    the percentage completion.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-gearmanclient.jobstatus-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">job_handle</code></em></dt>

     <dd>

      <p class="para">
       由 Gearman 服务器指派的工作句柄。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-gearmanclient.jobstatus-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   An array containing status information for the job corresponding to the supplied
   job handle.  The first array element is a boolean indicating whether the job is
   even known, the second is a boolean indicating whether the job is still running,
   and the third and fourth elements correspond to the numerator and denominator
   of the fractional completion percentage, respectively.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-gearmanclient.jobstatus-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4234">
    <p><strong>Example #1 Monitor the status of a long running background job</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;create&nbsp;our&nbsp;object&nbsp;*/<br /></span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">GearmanClient</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;add&nbsp;the&nbsp;default&nbsp;server&nbsp;*/<br /></span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;run&nbsp;reverse&nbsp;client&nbsp;*/<br /></span><span style="color: #0000BB">$job_handle&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">doBackground</span><span style="color: #007700">(</span><span style="color: #DD0000">"reverse"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"this&nbsp;is&nbsp;a&nbsp;test"</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">returnCode</span><span style="color: #007700">()&nbsp;!=&nbsp;</span><span style="color: #0000BB">GEARMAN_SUCCESS</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"bad&nbsp;return&nbsp;code\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #0000BB">$done&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">;<br />do<br />{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sleep</span><span style="color: #007700">(</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$stat&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">jobStatus</span><span style="color: #007700">(</span><span style="color: #0000BB">$job_handle</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">])&nbsp;</span><span style="color: #FF8000">//&nbsp;the&nbsp;job&nbsp;is&nbsp;known&nbsp;so&nbsp;it&nbsp;is&nbsp;not&nbsp;done<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$done&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Running:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;(</span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]&nbsp;?&nbsp;</span><span style="color: #DD0000">"true"&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">"false"</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">",&nbsp;numerator:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">]&nbsp;.&nbsp;</span><span style="color: #DD0000">",&nbsp;denomintor:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #0000BB">3</span><span style="color: #007700">]&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br />while(!</span><span style="color: #0000BB">$done</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"done!\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

     <div class="example-contents"><p>以上例程的输出类似于：</p></div>
     <div class="example-contents screen">
<div class="cdata"><pre>
Running: true, numerator: 3, denomintor: 14
Running: true, numerator: 6, denomintor: 14
Running: true, numerator: 9, denomintor: 14
Running: true, numerator: 12, denomintor: 14
Running: false, numerator: 0, denomintor: 0
done!
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-gearmanclient.jobstatus-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="gearmanclient.dostatus.html" class="methodname" rel="rdfs-seeAlso">GearmanClient::doStatus()</a> - Get the status for the running task</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="gearmanclient.geterrno.html">GearmanClient::getErrno</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="gearmanclient.ping.html">GearmanClient::ping</a></div>
 <div class="up"><a href="class.gearmanclient.html">GearmanClient</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
